package org.fightingliu.demo.listener;


import lombok.extern.slf4j.Slf4j;
import org.fightingliu.demo.handler.RedisMessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * @author : LiuChao
 * @description : TODO
 * @date : 2025-04-16 21:23:07
 */
@Slf4j
@Component
@ConditionalOnBean(RedisMessageHandler.class)
public class RedisSubscriber implements MessageListener {

    @Autowired
    private Map<String, RedisMessageHandler> redisMessageHandlerMap;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String channel = new String(message.getChannel());
        redisMessageHandlerMap.get(channel).handle(message);
    }
}
